package com.ruoyi.appService.wxuser.controller;

import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.appService.wxuser.domain.ZWxuser;
import com.ruoyi.appService.wxuser.domain.loginVO;
import com.ruoyi.appService.wxuser.mapper.ZWxuserMapper;
import com.ruoyi.appService.wxuser.service.IZWxuserService;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.framework.web.service.WxTokenService;
import com.ruoyi.framework.web.service.wxUserRedis;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import javax.servlet.http.HttpServletRequest;

/**
 * 微信用户Controller
 *
 * @author ç¹è½æ²
 * @date 2025-03-31
 */
@RestController
@CrossOrigin
@RequestMapping("/appManager/wxuser")
public class ZWxuserController extends BaseController {


    @Autowired
    private IZWxuserService zWxuserService;

    @Autowired
    private ZWxuserMapper zWxuserMapper;


    /**
     * 查询微信用户列表
     */
    @PreAuthorize("@ss.hasPermi('appManager:wxuser:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZWxuser zWxuser) {
        startPage();
        List<ZWxuser> list = zWxuserService.selectZWxuserList(zWxuser);
        return getDataTable(list);
    }


    /**
     * 获取微信用户详细信息
     */
    @PreAuthorize("@ss.hasPermi('appManager:wxuser:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(zWxuserService.selectZWxuserById(id));
    }


    /**
     * 新增微信用户
     */
    @PreAuthorize("@ss.hasPermi('appManager:wxuser:add')")
    @Log(title = "微信用户", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZWxuser zWxuser) {
        zWxuserMapper.insert(zWxuser);
        return AjaxResult.success("200","新增成功");
    }


    /**
     * 修改微信用户
     */
    @PreAuthorize("@ss.hasPermi('appManager:wxuser:edit')")
    @Log(title = "微信用户", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZWxuser zWxuser) {

        System.out.println(zWxuser);
        UpdateWrapper<ZWxuser> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id", zWxuser.getId());
        zWxuserMapper.update(zWxuser, updateWrapper);


        return AjaxResult.success("200","修改成功");

    }


    /**
     * 删除微信用户
     */
    @PreAuthorize("@ss.hasPermi('appManager:wxuser:remove')")
    @Log(title = "微信用户", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(zWxuserService.deleteZWxuserByIds(ids));
    }







    //    微信登录功能
    @PostMapping("/login")
    public AjaxResult login(@RequestBody loginVO loginvo) {
        return  zWxuserService.login(loginvo);
    }


    //    微信注册功能
    @PostMapping("/register")
    public AjaxResult register(@RequestBody ZWxuser wxuser) {
        return  zWxuserService.register(wxuser);
    }




    //    绑定学号
    @PostMapping("/bindStudentID")
    public AjaxResult bindTelephone(@RequestBody ZWxuser wxuser, HttpServletRequest request) {
        return zWxuserService.bindTelephone(wxuser,request);
    }


    //    重置密码
@PostMapping("/restPassword")
 public AjaxResult restPassword(@RequestBody ZWxuser wxuser) {
     return zWxuserService.restPassword(wxuser);
 }



    //  获取微信用户详细信息
@GetMapping("/wxuserInfo")
public AjaxResult wxuserInfo( HttpServletRequest request) {
    return new AjaxResult(200,"查询成功", zWxuserService.wxuserInfo(request));
}




//    修改手机号
@PostMapping("/restTelephone")
public AjaxResult restTelephone(@RequestBody loginVO loginvo ,HttpServletRequest request){
    return  zWxuserService.restTelephone(loginvo,request);
}






//修改个人信息
@PostMapping("/updateWXuser")
public AjaxResult updateWXuser(@RequestBody ZWxuser zwxuser ,HttpServletRequest request){
        zWxuserService.updateWXuser(zwxuser,request);
    return AjaxResult.error(200, "用户修改成功");
}



@PostMapping("/test")
    public void test(){

        System.out.println();
}








//    /**
//     * 导出微信用户列表
//     */
//    @PreAuthorize("@ss.hasPermi('appManager:wxuser:export')")
//    @Log(title = "微信用户", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ZWxuser zWxuser)
//    {
//        List<ZWxuser> list = zWxuserService.selectZWxuserList(zWxuser);
//        ExcelUtil<ZWxuser> util = new ExcelUtil<ZWxuser>(ZWxuser.class);
//        util.exportExcel(response, list, "微信用户数据");
//    }


}
